package com.huawei.esdk.uc.sametime.widgets;

import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

import com.huawei.esdk.uc.sametime.international.Messages;
import com.huawei.esdk.uc.sametime.util.PersonInviteUtil;

/**
 * 按号码邀请与会人的弹出框实现类
 * @author l00206777
 * 
 */
public class InviteByNumberDialog extends Dialog
{
    private Text numberText;

    /**
     * Create the dialog.
     * @param parentShell
     */
    public InviteByNumberDialog(Shell parentShell)
    {
        super(parentShell);
    }

    /**
     * Create contents of the dialog.
     * @param parent
     */
    @Override
    protected Control createDialogArea(Composite parent)
    {
        Composite container = (Composite) super.createDialogArea(parent);
        container.setLayout(null);

        numberText = new Text(container, SWT.BORDER);
        numberText.setBounds(125, 21, 123, 23);

        Label InviteNumberLabel = new Label(container, SWT.NONE);
        InviteNumberLabel.setBounds(10, 24, 109, 17);
        InviteNumberLabel.setText(Messages.InviteByNumberDialog_NUM_TO_INVITE);

        return container;
    }

    /**
     * 重写这个方法,为了能够设置标题
     * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell)
     */
    @Override
    protected void configureShell(Shell shell)
    {
        super.configureShell(shell);
        shell.setText(Messages.InviteByNumberDialog_INVITE_BY_NUM_TITLE);
    }

    /**
     * Create contents of the button bar.
     * @param parent
     */
    @Override
    protected void createButtonsForButtonBar(Composite parent)
    {
        super.createButtonsForButtonBar(parent);
    }

    /**
     * 本来是在createButtonsForButtonBar里面生成两个button,并且给okbutton设置监听器,在里面赋值的,但赋值时候,
     * numberText都被释放掉了,所以重写这个方法,在默认的okbutton按下时候,nuberText释放之前来赋值
     * @see org.eclipse.jface.dialogs.Dialog#okPressed()
     */
    @Override
    protected void okPressed()
    {
        PersonInviteUtil.getInstance().setNumberToInvite(""); //$NON-NLS-1$
        if (null != numberText)
        {
            PersonInviteUtil.getInstance().setNumberToInvite(
                    numberText.getText().trim());
        }
        super.okPressed();
    }

    /**
     * Return the initial size of the dialog.
     */
    @Override
    protected Point getInitialSize()
    {
        return new Point(280, 150);
    }

}
